import { registerDecorator, ValidationOptions, ValidationArguments } from 'class-validator'

export function checkPassword(validationOptions?: ValidationOptions) {
   return function (object: Object, propertyName: string) {
      registerDecorator({
         name: 'checkPassword',
         target: object.constructor,
         propertyName: propertyName,
         options: validationOptions,
         validator: {
            validate(value: any, args: ValidationArguments) {
               return !(value == (args.object as any).oldPassword)
            }
         }
      })
   }
}
